package com.project.model;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.project.dto.JoinFriendDto;
import com.project.dto.JoinTtalkDto;
import com.project.dto.TFriendDto;
import com.project.dto.TPeopleDto;
import com.project.dto.TPicDto;
import com.project.dto.TWallDto;
import com.project.dto.SqlDaoSuport;
import com.project.dto.TtalkDto;

public class TPeopleUserManager extends SqlDaoSuport implements ITPeopleUser {
	
	public TPeopleUserManager(){
		super();
	}
	public TPeopleUserManager(String pass){
		super(pass);
	}
	
	@Override
	public int addTpeopleUser(TPeopleDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("addTpeopleUser",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	@Override
	public int updateTpeopleUser(TPeopleDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().update("updateTpeopleUser", tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	@Override
	public TPeopleDto login(TPeopleDto tDto) {
		TPeopleDto result = null;
		try {
			result = (TPeopleDto)this.getSqlMapClient().queryForObject("login", tDto);
		} catch (SQLException e) {
			System.out.println(e);
		}
		return result;
	}
	@Override
	public List<TPeopleDto> connTPeopleUser(String conn) {
		List<TPeopleDto> result = null;
		try {
			result = (List<TPeopleDto>)this.getSqlMapClient().queryForList("connTPeopleUser", conn);
		} catch (SQLException e) {
			System.out.println(e);
		}
		return result;
	}
	@Override
	public int updateUserState(String email) {
		int count = 1;
		try {
			this.getSqlMapClient().update("updateUserState", email);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	public int updateTpeople(TPeopleDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().update("updateTpeople", tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	public int writeTwall(TWallDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("writeTwall",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	public List<TWallDto> getTWallList(String board){
		List<TWallDto> result=null;
		try {
			result=
		 (List<TWallDto>)getSqlMapClient().queryForList("getTWallList",board);
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//

	public int replyinsert(TWallDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("replyinsert",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
		
	}
	@Override
	public int replyupdate(TWallDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().update("replyupdate", tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	@Override
	public TPeopleDto selectuser(String email) {
		TPeopleDto result = null;
		try {
			result = (TPeopleDto)this.getSqlMapClient().queryForObject("selectuser", email);
		} catch (SQLException e) {
			System.out.println(e);
		}
		return result;
	}
	@Override
	public List<TPeopleDto> findTpeopleUser(String name) {
		List<TPeopleDto> result = null;
		try {
			result = (List<TPeopleDto>)this.getSqlMapClient().queryForList("findTpeopleUser", name);
		} catch (SQLException e) {
			System.out.println(e);
		}
		return result;
	}
	
	public int regiTFriendDto(TFriendDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("regiTFriendDto",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	
	public int updateTFriendDto(TFriendDto tDto) {
		int count2 = 1;
		try {
			this.getSqlMapClient().update("updateTFriendDto", tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count2 = -1;
		}
		return count2;
	}
	
//	@Override
//	public JoinFriendDto findTFriendDto(String email) {
//		JoinFriendDto result= null;
//		try {
//			result=(JoinFriendDto)this.getSqlMapClient().queryForObject("findTFriendDto",email);
//		} catch (Exception e) {
//			System.out.println("findTFriendDto : "+e);
//		}		
//		return result;
//	}
	
	public List<JoinFriendDto> getTMateListDto(String email){
		List<JoinFriendDto> result=null;
		try {
			result=
		 (List<JoinFriendDto>)getSqlMapClient().queryForList("getTMateListDto", email);
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//
	@Override
	public TPeopleDto friendDto(String email) {
		TPeopleDto result= null;
		try {
			result=(TPeopleDto)this.getSqlMapClient().queryForObject("friendDto",email);
		} catch (Exception e) {
			System.out.println("findTpeopleUser : "+e);
		}		
		return result;
	}
	@Override
	public int del(int wcode){
		
			int count=1;
			try{
				this.getSqlMapClient().delete("del",wcode);
			}catch (Exception e) {
				count=-1;
				System.out.println(e);
			}
			return count;
	}
	public List<TFriendDto> friendList(String email){
		List<TFriendDto> result=null;
		try {
			result=
		 (List<TFriendDto>)getSqlMapClient().queryForList("friendList", email);
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//
	public int addFile(TPeopleDto tDto) {
		 int count=1;
		  
		  try {
		   this.getSqlMapClient().update("imgup",tDto);
		  } catch (SQLException e) {
		   count=-1;
		   e.printStackTrace();
		  }			  
		  return count;
	}
	public int addTpic(TPicDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("addTpic",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	@Override
	public List<TPicDto> allTpic(String pboard,int page) {
		List<TPicDto> result = null;
		Map<String, Object> maps = new HashMap<String, Object>();
		
		maps.put("pboard", pboard);
		maps.put("page", page);
		
		try {
			result = (List<TPicDto>)this.getSqlMapClient().queryForList("allTpic",maps);
		} catch (SQLException e) {
			System.out.println(e);
		}
		return result;
	}
	@Override
	public TPicDto getTpic(int pcode) {
		TPicDto dto = null;		
		
		try {
			dto = (TPicDto)this.getSqlMapClient().queryForObject("getTpic", pcode);
		} catch (SQLException e) {
			System.out.println(e);
		}
		
		return dto;
	}
	@Override
	public int tpicreply(TPicDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("tpicreply",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
		
	
	}
	public List<TPicDto> allreply(int pcode) {
		List<TPicDto> result = null;
		try {
			result = (List<TPicDto>)this.getSqlMapClient().queryForList("allreply",pcode);
		} catch (SQLException e) {
			System.out.println(e);
		}
		return result;
	}
	@Override
	public int delpic(int pcode) {
		
			
			int count=1;
			try{
				this.getSqlMapClient().delete("delpic",pcode);
			}catch (Exception e) {
				count=-1;
				System.out.println(e);
			}
			return count;
	
	}
	@Override
	public int logoutUserState(String email) {
		
			int count = 1;
			try {
				this.getSqlMapClient().update("logoutUserState", email);
			} catch (SQLException e) {
				System.out.println(e);
				count = -1;
			}
			return count;
		}
	//------------------------
	public List<JoinFriendDto> getTtalkFriendList(JoinFriendDto fdto){
		List<JoinFriendDto> result=null;
		System.out.println("fdto===="+fdto);
		try {
			result=
		 (List<JoinFriendDto>)getSqlMapClient().queryForList("getTtalkFriendList", fdto);
			System.out.println("result===="+result);
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//
	@Override
	public int writeTtalkDto(TtalkDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("writeTtalkDto",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	@Override
	public int writeJoinTtalkDto(JoinTtalkDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().insert("writeJoinTtalkDto",tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	public List<JoinTtalkDto> getTtalkContList(String email){
		List<JoinTtalkDto> result=null;
		try {
			result=
		 (List<JoinTtalkDto>)getSqlMapClient().queryForList("getTtalkContList", email);
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//
	
	public List<JoinTtalkDto> getTtalkSendList(String email){
		List<JoinTtalkDto> result=null;
		try {
			result=
		 (List<JoinTtalkDto>)getSqlMapClient().queryForList("getTtalkSendList", email);
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//
	
	public List<JoinFriendDto> getConnFriendList(JoinFriendDto cdto){
		List<JoinFriendDto> result=null;
		
		try {
			result=
		 (List<JoinFriendDto>)getSqlMapClient().queryForList("getConnFriendList", cdto);
			
		} catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	}//
	
	@Override
	public int receiveDelTtalk(TtalkDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().update("receiveDelTtalk", tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
		
	@Override
	public int sendDelTtalk(TtalkDto tDto) {
		int count = 1;
		try {
			this.getSqlMapClient().update("sendDelTtalk", tDto);
		} catch (SQLException e) {
			System.out.println(e);
			count = -1;
		}
		return count;
	}
	public List<TPeopleDto> flist(String email) {

		List<TPeopleDto> result=null;
		try {
			result=
		 (List<TPeopleDto>)getSqlMapClient().queryForList("flist", email);
		}catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	
	}
	public int getTpicCount(String email) {
		int count = 0;
		
		try {
			count=(Integer) this.getSqlMapClient().queryForObject("getTpicCount", email);
		} catch (SQLException e) {
			System.out.println(e);
			
		}
		return count;
	}
	public int getCount(String email) {
		int count = 0;
		
		try {
			count=(Integer) this.getSqlMapClient().queryForObject("getCount", email);
		} catch (SQLException e) {
			System.out.println(e);
			
		}
		return count;
	}
	public List<TWallDto> getTWallList1(String board,int page) {
		List<TWallDto> result=null;
		
		Map<String, Object> maps=new HashMap<String, Object>();
		
		maps.put("board",board);
		maps.put("page", page);
		
		try {
			result=
				 (List<TWallDto>)getSqlMapClient().queryForList("getTWallList1",maps);
		} catch (SQLException e) {
			System.out.println(e);
			
		}
		return result;
		
	
		
	}
	
	public List<TWallDto> allTNews(String email) {
		List<TWallDto> result=null;
		
		
		
		try {
			result=
				 (List<TWallDto>)getSqlMapClient().queryForList("allTNews", email);
		}catch (Exception e) {
			System.out.println(e);
		}		 
		return result;
	
	}
}
